<?php
include("function.php");
judgeLogin();

function showCountResult($sql){
	$re=mysql_query($sql);
	$count=mysql_num_rows($re);
	return $count;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--<meta name="keywords" content="食品笔记,食品,食品安全,饮食,饮食安全,生活"><!--SEO关键字-->
<meta name="description" content="食品笔记，你的饮食安全卫士"><!--SEO描述-->
<link rel="shortcut icon" type="image/ico" href="images/favicon.ico"><!--选项卡图标-->
<title>食品笔记 - 让生活更健康</title>
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="css/style.css">

<!--[if ie]>
<link rel="stylesheet" href="css/ie.css">
<script type="text/javascript" src="js/DD_belatedPNG.js" ></script>
<script type="text/javascript">
DD_belatedPNG.fix('.png');/*在需要png透明的元素里面加上.png样式即可（class="png"）*/
</script>
<![endif]-->
</head>
<body>
	<div class="header w pr"><!-- header -->
		<div class="index-header w960 bc pr">
			<a href="home.php" class="score_logo score_img dib png fl mt10"></a>
			<div class="header_right fr">
				<ul class="header_nav fl tc fb f12 h">
					<li><a href="home.php">首 页</a></li>
					<li><a href="report.php">饮食报告</a></li>
					<li><a href="newsmap.php">食品新闻</a></li>
					<li><a href="food.php" class="header_nav_hover">选食专栏</a></li>
					<li><a href="timeline.php">时光轴</a></li>
					<li><a href="share.php">分享</a></li>
				</ul>

				<a href="massage.php" class="header_myMessage tc fr ml5" title="私信"><?php echo showCountMassage($_SESSION['login_mail']);?></a><!-- 私信 -->

				<div class="header_myInfo fr f14 h pr">
					<a href="#" class="header_setup"><img src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo showUserPhoto();endif;?>" alt="" class="fl" /></a><!-- user_avatar -->
					<a href="#" class="fl header_setup"><?php echo showUserName();?></a><!-- user_nickname -->
					<div class="header_myInfoArrow score_img fl"></div>
					<ul class="header_hideInfo none pa tc w"><!-- hide_info -->
						<li><a href="#" class="header_setup">个人设置</a></li>
						<li><a href="modifymail.php">修改邮箱</a></li>
						<li><a href="password.php">修改密码</a></li>
						<li><a href="login_out.php">退出登录</a></li>
					</ul>
				</div>	
			</div>
			<div class="score_img content_top pa"></div>
		</div>
	</div><!-- end_header -->

	<div class="score_main pr oh h"><!-- score_main -->
		<div class="main w960 bc h">
			<div class="score_sider fl mt20 pr">
			<ul class="tr fr food_sider_ul f18 pr">
					<li>
						<a href="" class="food_BigCate">调味品</a>
						<div class="food_detailedInfo">
							<a href="food.php?category=2" class="food_category">调味酱</a>
							<a href="food.php?category=3" class="food_category">醋</a>
							<a href="food.php?category=4" class="food_category">火锅调料</a>
							<a href="food.php?category=5" class="food_category">泡打粉</a>
							<a href="food.php?category=6" class="food_category">味精/鸡精</a>
							<a href="food.php?category=7" class="food_category">咖喱</a>
							<a href="food.php?category=8" class="food_category">料酒</a>
							<a href="food.php?category=9" class="food_category">盐/糖</a>
							<a href="food.php?category=10" class="food_category">调味汁/粉</a>
							<a href="food.php?category=11" class="food_category">腐乳</a>
							<!--<a href="food.php?category=12" class="food_category">蛋糕粉</a>
							<a href="food.php?category=13" class="food_category">西式酱</a>
							<a href="food.php?category=14" class="food_category">酱菜/腌制品</a>
							<a href="food.php?category=15" class="food_category">香辛料</a>
							<a href="food.php?category=20" class="food_category">鱼/贝露</a>-->
						</div>
					</li>
					<li>
						<a href="" class="food_BigCate">乳制品</a>
						<div class="food_detailedInfo">
							<a href="food.php?category=22" class="food_category">酸奶</a>
							<a href="food.php?category=23" class="food_category">新鲜低温奶</a>
							<a href="food.php?category=26" class="food_category">乳酪/芝士/炼乳</a>
							<a href="food.php?category=28" class="food_category">冰淇淋</a>
							<a href="food.php?category=30" class="food_category">常温奶</a>
							<a href="food.php?category=31" class="food_category">豆奶</a>
							<a href="food.php?category=33" class="food_category">儿童奶</a>
							<a href="food.php?category=34" class="food_category">成人奶粉</a>
						</div>
					</li>
					<li>
						<a href="" class="food_BigCate">休闲食品</a>
						<div class="food_detailedInfo">
							<a href="food.php?category=35" class="food_category">膨化食品</a>
							<a href="food.php?category=37" class="food_category">巧克力</a>
							<a href="food.php?category=39" class="food_category">果冻/布丁/龟苓膏</a>
							<a href="food.php?category=40" class="food_category">蜜饯果脯</a>
							<a href="food.php?category=41" class="food_category">速冻食品</a>
							<a href="food.php?category=42" class="food_category">豆类零食</a>
							<a href="food.php?category=44" class="food_category">海味零食</a>
							<a href="food.php?category=46" class="food_category">地方特产类</a>
							<a href="food.php?category=49" class="food_category">小吃类</a>
							<a href="food.php?category=51" class="food_category">鸡鸭禽类</a>
							<a href="food.php?category=53" class="food_category">糖果</a>
							<a href="food.php?category=54" class="food_category">肉脯肉松</a>
							<a href="food.php?category=56" class="food_category">坚果/干果</a>
							<a href="food.php?category=58" class="food_category">口香糖</a>
					
						</div>	
					</li>
					<li>
						<a href="" class="food_BigCate">酒</a>
						<div class="food_detailedInfo">
							<a href="food.php?category=60" class="food_category">啤酒</a>
							<a href="food.php?category=62" class="food_category">白酒</a>
							<a href="food.php?category=63" class="food_category">滋补酒</a>
							<!--<a href="food.php?category=65" class="food_category">果酒</a>-->
							<a href="food.php?category=66" class="food_category">葡萄酒</a>
							<!--<a href="food.php?category=68" class="food_category">黄酒</a>-->
							<a href="food.php?category=69" class="food_category">预调酒</a>
						</div>	
					</li>
					<li>
						<a href="" class="food_BigCate">饮料</a>
						<div class="food_detailedInfo">
							<a href="food.php?category=25" class="food_category">乳酸菌饮料</a>
							<a href="food.php?category=64" class="food_category">蜂蜜/柚子茶/秋梨</a>
							<a href="food.php?category=73" class="food_category">果汁/蔬菜汁</a>
							<!--<a href="food.php?category=75" class="food_category">碳酸饮料</a>
							<a href="food.php?category=76" class="food_category">乳酸饮料</a>-->
							<a href="food.php?category=78" class="food_category">果醋饮料</a>
							<a href="food.php?category=80" class="food_category">维生素饮料</a>
							<a href="food.php?category=81" class="food_category">运动饮料</a>
							<a href="food.php?category=83" class="food_category">水</a>
							<a href="food.php?category=85" class="food_category">植物饮料</a>
							<a href="food.php?category=87" class="food_category">果汁奶饮料</a>
						</div>	
					</li>
					<li>
						<a href="" class="food_BigCate">方便食品</a>
						<div class="food_detailedInfo">
							<a href="food.php?category=16" class="food_category">方便面</a>
							<a href="food.php?category=18" class="food_category">方便汤料</a>
							<a href="food.php?category=21" class="food_category">方便主食</a>
							<a href="food.php?category=24" class="food_category">罐头</a>
							<a href="food.php?category=27" class="food_category">肉制品</a>
							<a href="food.php?category=29" class="food_category">方便粉丝/米线</a>
							<a href="food.php?category=32" class="food_category">方便粥类</a>
							<a href="food.php?category=36" class="food_category">方便米饭</a>
							<a href="food.php?category=38" class="food_category">酱菜</a>
						</div>	
					</li>
					<li>
						<a href="" class="food_BigCate">油粮</a>
					<div class="food_detailedInfo">
						<!--<a href="food.php?category=17" class="food_category">香油</a>
						<a href="food.php?category=19" class="food_category">蚝油</a>-->
						<a href="food.php?category=43" class="food_category">食用油</a>
						<a href="food.php?category=45" class="food_category">面粉</a>
						<a href="food.php?category=47" class="food_category">豆制品</a>
						<a href="food.php?category=48" class="food_category">面条</a>
						<a href="food.php?category=50" class="food_category">大米</a>
						<!--<a href="food.php?category=52" class="food_category">杂粮</a>-->
					</div>	
					</li>
					<li>
						<a href="" class="food_BigCate">冲调饮品</a>
						<div class="food_detailedInfo">
							<a href="food.php?category=55" class="food_category">咖啡</a>
							<a href="food.php?category=57" class="food_category">糊状冲调品</a>
							<a href="food.php?category=59" class="food_category">奶茶/巧克力粉</a>
							<a href="food.php?category=61" class="food_category">果味冲调品</a>
							<!--<a href="food.php?category=67" class="food_category">膏/姜茶</a>-->
						</div>	
					</li>
					<li>
						<a href="" class="food_BigCate">饼干糕点</a>
						<div class="food_detailedInfo">
							<a href="food.php?category=70" class="food_category">饼干</a>
							<a href="food.php?category=72" class="food_category">点心类</a>
							<a href="food.php?category=74" class="food_category">蛋糕/面包</a>
						</div>	
					</li>
					<li>
						<a href="" class="food_BigCate">婴幼儿食品</a>
						<div class="food_detailedInfo">
							<a href="food.php?category=79" class="food_category">辅食</a>
							<!--<a href="food.php?category=82" class="food_category">孕妇奶粉</a>-->
							<a href="food.php?category=77" class="food_category">婴幼儿奶粉</a>
						</div>	
					</li>
					<li>  
						<a href="" class="food_BigCate">茶叶/茶包</a>
						<div class="food_detailedInfo">
							<a href="food.php?category=86" class="food_category">绿茶</a>
							<!--<a href="food.php?category=86" class="food_category">乌龙茶</a>-->
							<a href="food.php?category=88" class="food_category">花茶</a>
							<a href="food.php?category=89" class="food_category">袋泡茶</a>
							<a href="food.php?category=90" class="food_category">红茶</a>
							<a href="food.php?category=91" class="food_category">普洱茶</a>
							<!--<a href="food.php?category=92" class="food_category">花果茶</a>-->
						</div>	
					</li>
					<li>
						<a href="" class="food_BigCate">其他保健品</a>
						<div class="food_detailedInfo">
							<a href="food.php?category=93" class="food_category">其他保健食品</a>
						</div>	
					</li>
				</ul>
				
			</div>
			<div class="content fr pr">
			<?php 
				if(!empty($_GET['category'])){$category = $_GET['category'];}
				if( $category ){ $cond = "`category_id` = '".$category."' order by `id` asc"; }
			
				$page=basename($_SERVER['PHP_SELF']);
				$pagenum=9;
				$start = rand(200,250);
				$end = rand(300,350);
				if($cond){ $sql = "select * from `food_basic` where $cond";}
				else{ $sql = "select * from `food_basic` where id between $start and $end order by id asc";}
				$cs="&category=".urlencode($category);
				$num = showCountResult($sql);
				$sql_1=$sql;
				$sql=page_r($sql,$page,$pagenum,$cs);
				$query=mysql_query($sql)or die(mysql_error());
				$number = mysql_num_rows($query);
				
				if($category): 
				$query_1 = mysql_query("select `category` from food_category where id = $category") or die(mysql_error());
				$row_1 = mysql_fetch_array($query_1);
			?>
				<div class="food_searchTitle ml20 f16">一共找到“<span class="food_strength"><?php echo $row_1['category'];?></span>”的搜索结果<span class="food_strength"><?php echo $num;?></span>个</div>
			<?php endif; ?>
				<ul class="food_display bc ml20 mt20 tc oh">
			<?php
			for($i=1;$i<=$number;$i++)
			{
				$row = mysql_fetch_array($query);
		
			?>
			<?php
			$basic_id = $row['id'];
			$sql_trust = "select id from food_vote where basic_id = $basic_id";
			$query_trust = mysql_query($sql_trust) or die(mysql_error()) ;
			$num_trust = mysql_num_rows($query_trust);
			?>
					<li>
						<p><a href="food_detail.php?id=<?php echo $row['id'];?>"><img src="imageTemp/<?php echo $row['id'];?>_1.jpg" alt="" class="food_img" /></a></p>
						<p><a href="food_detail.php?id=<?php echo $row['id'];?>" class="c00297f"><?php echo $row['ch_name'];?></a></p>
						<p>食品安全信任指数：<?php if(is_numeric($row['trust'])): ?><span class='food_safetyIndex'><?php echo $row['trust'];?></span><?php else: echo $row['trust']; endif;?></p></p>
						
						<p><?php if($num_trust !== 0):echo '有<span style="color:red;">'.$num_trust.'</span>人投票';else:echo '暂时无人投票';endif;?></p>
					</li>
			<?php
			}//end for
			?>
				</ul>
				<div style='color:#636363' class='news_flip mb50 mt50 tc'>
					<?php 
					//翻页页码
					page($sql_1,$page,$pagenum,$cs); 
					?>
				</div>
			</div>
			
		</div>
	</div><!-- end_score_main -->
	
	
	<div class="footer w"><!-- footer -->
		<div class="w960 bc pr">
			<div class="content_footer score_img pa"></div>
			<div class="pt30 welcome-footer bc">
				<span class="iphone-app-img dib png fl"></span><a href="#" class="iphone-app f12 a3 fl">iphone应用</a><a href="foodnote.apk" class="android-app f12 a3 fr">android应用</a><span class="android-app-img dib png fr"></span>
			</div>
			<div class="welcome-about mb10">
				<p class="f12 tc"><a href="#" class="a3">关于我们</a><span class="ml10 mr10">|</span><a href="#" class="a3">使用条款</a><span class="ml10 mr10">|</span><a href="#" class="a3">常见问题</a></p>
			</div>
			<div class="welcome-about f12 tc">
				<p class="a3 f12 c91">Copyright &copy; 2011-2012 Foodnote&nbsp;&nbsp;&nbsp;&nbsp; 湘ICP备09004495号-5</p>
			</div>
		</div>
	</div><!-- end_footer -->

	<?php
		//判断是否新用户登录
		$login_mail = $_SESSION['login_mail'];
		$login_status = judgeNewUser($login_mail);
		
		//获取用户数据
		$userData = getUserBasicInfo($_SESSION['login_mail']);
		
		if($login_status == 0)
		{
			echo "<div class='novice_login png pa w'>";
		}else
		{
			echo "<div class='novice_login png pa w none'>";
		}
	?>
		<div class="personal_info bc oh pb50 pr">
			<div class="personal_close score_img pa"></div>
			<h2 class="personal_title ml50 mt20 mb20">个人信息录入</h2>
			
			<form action="home.php" method="post" class="ml50">
				<fieldset class="fl">
					<p class="mt10"><label for="" class="personal_label f22">性别</label></p>
					<p class="mt10"><small class="personal_small f14">请选择：男/女</small></p>
					<p class="mt10">
						<select class="score_text score_select pl5 pr5 " name="sex">
					<?php  
						if($userData['user_sex']=="男"):
						
							echo "<option value='男' selected >男</option>";
							echo "<option value='女'>女</option>";
						
						elseif($userData['user_sex']=="女"):
						
							echo "<option value='男'>男</option>";
							echo "<option value='女' selected>女</option>";
						
						else:
						
							echo "<option value='' selected>--</option>";
							echo "<option value='男'>男</option>";
							echo "<option value='女'>女</option>";
						endif;
					?>
								
						</select>
					</p>
					<p class="mt10"><label for="" class="personal_label f22">年龄</label></p>
					<p class="mt10"><small class="personal_small f14">不同的年龄对饮食的需求不同，例如:23</small></p>
					<p class="mt10"><input type="text" class="score_text zy_ageVal pl5 pr5" name="age" value="<?php echo $userData['user_age'];?>"/></p>
					<p class="mt10"><label for="" class="personal_label f22">现居地</label></p>
					<p class="mt10"><small class="personal_small f14">请输入您现居地的省份名，例如:湖南</small></p>

					<p class="mt10">
						<select class="score_text score_select pl5 pr5 " name="city">
							<option value='<?php echo $userData['user_city'];?>' selected><?php echo $userData['user_city'];?></option>
							<option value='安徽'>安徽</option>
							<option value='福建'>福建</option>
							<option value='港澳台藏'>港澳台藏</option>
							<option value='甘肃'>甘肃</option>
							<option value='广东'>广东</option>
							<option value='广西'>广西</option>
							<option value='贵州'>贵州</option>
							<option value='海南'>海南</option>
							<option value='河北'>河北</option>
							<option value='黑龙江'>黑龙江</option>
							<option value='河南'>河南</option>
							<option value='湖北'>湖北</option>
							<option value='湖南'>湖南</option>
							<option value='江苏'>江苏</option>
							<option value='江西'>江西</option>
							<option value='吉林'>吉林</option>
							<option value='辽宁'>辽宁</option>
							<option value='内蒙古'>内蒙古</option>
							<option value='宁夏'>宁夏</option>
							<option value='青海'>青海</option>
							<option value='山东'>山东</option>
							<option value='山西'>山西</option>
							<option value='陕西'>陕西</option>
							<option value='四川'>四川</option>
							<option value='云南'>云南</option>
							<option value='新疆'>新疆</option>
							<option value='浙江'>浙江</option>
							<option value='直辖市'>直辖市</option>
						</select>
					</p>

					<p class="mt10"><label for="" class="personal_label f22">体重</label></p>
					<p class="mt10"><small class="personal_small f14">不同的体重对饮食的需求不同，单位：kg</small></p>
					<p class="mt10"><input type="text" class="score_text zy_weightVal pl5 pr5" name="weight" value="<?php echo $userData['weight'];?>"/> kg</p>
					<input type="hidden" value="<?php echo basename($_SERVER['PHP_SELF']);?>" name="fileName" />
					<input type="hidden" value="true" name="submited" />
					<input type="submit" value="确认提交" name="submit" class="personal_submit pa f18" />
				</fieldset>
			</form>
			<form method="post" action ="upload.php" enctype="multipart/form-data" target="hidden_frame" class="none">
				<fieldset>
					<input type="file" name="photo" id="photo" onchange="cli('p_submit');"/>
					<input type="submit" name="p_submit" value="保存" id="p_submit">
					<iframe name='hidden_frame' id="hidden_frame" style="border:none;" onreadystatechange="reflesh('<?php echo $_SESSION[login_mail]?>');"></iframe>
				</fieldset>
			</form>
			<form action="home.php" method="post" class="ml50">
				<fieldset>
					<a href="javascript:void(0)" onclick="cli('photo');"><img id="img" src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo showUserPhoto();endif;?>" class="personal_avatar pa" />
					<span class="pa click_upload">+点击上传头像</span>
					</a>
					<a href="javascript:void(0)" class="pa avatar_refresh" onclick="reflesh('<?php echo $_SESSION[login_mail]?>');">刷新</a>
				</fieldset>
			</form>
		</div>
	</div>
	<!-- JavaScript -->
<script type="text/javascript" src="js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>

<script type="text/javascript">  
 
 function cli(id){  
		var sub = document.getElementById(id);
   sub.click();  
//   if (/msie/i.test(navigator.userAgent)) //IE  
//   {  
//      sub.fireEvent("onclick");  
//   } else {  
//      var e = document.createEvent('MouseEvent');  
//      e.initEvent('click', false, false);  
//      sub.dispatchEvent(e);  
//   }
}

function reflesh(user){
	image_src="image.php?user_mail="+user+"&math="+Math.random(1);
	//alert(image_src);
	document.getElementById("img").src=image_src;
	
	}
</script> 
<div class="none">
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Fbba169f4f4508eb5cc1c5618eeb3c59d' type='text/javascript'%3E%3C/script%3E"));
</script>
</div>
</body>

</html>